home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0111_MS Excel XLOPER Structure.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  7KB  |  204 lines

  1. (*
  2.    For reference...  Here are the microsoft C and my borland Pascal versions
  3. of the Excel "xloper" structures.  Thanks for the help!
  4. Notes:  1) For each variant of the union in the C version of the xloper
  5. type there is a single comment starting "xlType...", "xlFlow...", ...
  6. these are actually integers from #define statements in the .H file.  I've
  7. used these as selectors in my "record case ..." statements (and declared
  8. them as "const" in my pascal source) and eliminated them from the comments.
  9. 2) A nice compare and contrast:  Had microsoft put the xltype word (which is
  10. at the end of the structure "xloper") first, I could have used it in my case
  11. selector as in "record case xltype:word of...",  the two bytes that xltype
  12. occupies would become somewhat of a runtime type selector (a definite pascal
  13. advantage) but on the other hand, by putting it at the end, the same address
  14. of this data item can directly typecast to one of the union's member types
  15. once xltype has been examined (you do it by hand...) a C advantage (unless
  16. you are using Borland Pascal :).  3) Since Pascal does not allow "unions
  17. within unions" or "variants of variants" I've declared each sub-union
  18. (variant) as a separate type, which is legal pascal.  Same effect.  4) I've
  19. taken liberties in renaming some fields to make them more readable for me :}
  20. 5) The C version is 88 lines long, the Pascal one is 85.  /*could it be the
  21. three lines I deleted from the comments???*/
  22.  
  23. *******************c version*****************************************
  24.  
  25. /*
  26. ** XLREF structure
  27. **
  28. ** Describes a single rectangular reference
  29. */
  30.  
  31. typedef struct xlref
  32. {
  33.     WORD rwFirst;
  34.     WORD rwLast;
  35.     BYTE colFirst;
  36.     BYTE colLast;
  37. } XLREF, FAR *LPXLREF;
  38.  
  39.  
  40. /*
  41. ** XLMREF structure
  42. **
  43. ** Describes multiple rectangular references.
  44. ** This is a variable size structure, default
  45. ** size is 1 reference.
  46. */
  47.  
  48. typedef struct xlmref
  49. {
  50.     WORD count;
  51.     XLREF reftbl[1];                        /* actually reftbl[count] */
  52. } XLMREF, FAR *LPXLMREF;
  53.  
  54.  
  55. /*
  56. ** XLOPER structure
  57. **
  58. ** Excel's fundamental data type: can hold data
  59. ** of any type. Use "R" as the argument type in the
  60. ** REGISTER function.
  61. **/
  62.  
  63. typedef struct xloper
  64. {
  65.     union
  66.     {
  67.         double num;                     /* xltypeNum */
  68.         LPSTR str;                      /* xltypeStr */
  69.         WORD bool;                      /* xltypeBool */
  70.         WORD err;                       /* xltypeErr */
  71.         short int w;                    /* xltypeInt */
  72.         struct
  73.         {
  74.             WORD count;                 /* always = 1 */
  75.             XLREF ref;
  76.         } sref;                         /* xltypeSRef */
  77.         struct
  78.         {
  79.             XLMREF far *lpmref;
  80.             DWORD idSheet;
  81.         } mref;                         /* xltypeRef */
  82.         struct
  83.         {
  84.             struct xloper far *lparray;
  85.             WORD rows;
  86.             WORD columns;
  87.         } array;                        /* xltypeMulti */
  88.         struct
  89.         {
  90.             union
  91.             {
  92.                 short int level;        /* xlflowRestart */
  93.                 short int tbctrl;       /* xlflowPause */
  94.                 DWORD idSheet;          /* xlflowGoto */
  95.             } valflow;
  96.             WORD rw;                    /* xlflowGoto */
  97.             BYTE col;                   /* xlflowGoto */
  98.             BYTE xlflow;
  99.         } flow;                         /* xltypeFlow */
  100.         struct
  101.         {
  102.             union
  103.             {
  104.                 BYTE far *lpbData;      /* data passed to XL */
  105.                 HANDLE hdata;           /* data returned from XL */
  106.             } h;
  107.             long cbData;
  108.         } bigdata;                      /* xltypeBigData */
  109.     } val;
  110.     WORD xltype;
  111. } XLOPER, FAR *LPXLOPER;
  112.  
  113.  
  114. *******************pascal version************************************
  115. *)
  116.  
  117. {*
  118. ** XLREF structure
  119. ** Describes a single rectangular reference
  120. *}
  121. type
  122.     xlref_ptr  = ^xlref_type;
  123.     xlref_type = record
  124.         FirstRow    : word;
  125.         LastRow     : word;
  126.         FirstCol    : byte;
  127.         LastCol     : byte;
  128.     end;
  129.  
  130. {*
  131. ** XLMREF structure
  132. ** Describes multiple rectangular references.
  133. ** This is a variable size structure, default
  134. ** size is 1 reference.
  135. *}
  136. type
  137.     xlmref_ptr   = ^xlmref_type;
  138.     xlmref_type  = record
  139.         count   : word; {count will never be more than 30 according to doc}
  140.         xlrefs  : array[1..32] of xlref_type;
  141.     end;
  142.  
  143. {*
  144. ** XLOPER structure
  145. ** Excel's fundamental data type: can hold data
  146. ** of any type. Use "R" as the argument type in the
  147. ** REGISTER function.
  148. **}
  149. type
  150.     flowarg_type = record case integer of
  151.         xlFlowRestart   : ( level   : integer; );
  152.         xlFlowPause     : ( tbctrl  : integer; );
  153.         xlFlowGoto      : ( SheetId : longint; );
  154.     end;
  155.  
  156. type
  157.     handle_type = record case integer of
  158.         1 : ( buff : pointer );  {*data passed to XL*}
  159.         2 : ( hand : record      {*data returned from XL*}
  160.                 offset   : word;
  161.                 selector : word;
  162.               end; );
  163.     end;
  164.  
  165. type
  166.     xloper_ptr  = ^xloper_type;
  167.     xloper_type = record
  168.         val : record case word of
  169.             xlTypeNum     : ( num  : double;  );
  170.             xlTypestr     : ( str  : ^string; );
  171.             xlTypeBool    : ( bool : word;    );
  172.             xlTypeErr     : ( err  : word;    );
  173.             xlTypeInt     : ( int  : integer; );
  174.             xlTypeSref    : ( sref : record
  175.                                 count   : word; {*always=1*}
  176.                                 xlref   : xlref_type;
  177.                               end; );
  178.             xlTypeRef     : ( mref : record
  179.                                 xlmref  : xlmref_ptr;
  180.                                 SheetId : longint;
  181.                               end; );
  182.             xlTypeMulti   : ( xlarray : record
  183.                                 xloper  : xloper_ptr;
  184.                                 rows    : word;
  185.                                 cols    : word;
  186.                               end; );
  187.             xlTypeFlow    : ( flow : record
  188.                                 flowarg : flowarg_type;
  189.                                 row     : word;
  190.                                 col     : byte;
  191.                                 xlflow  : byte;
  192.                               end; );
  193.             xlTypeBigdata : ( bigdata : record
  194.                                 handle  : handle_type;
  195.                                 len     : longint;
  196.                               end; );
  197.         end;
  198.         xltype : word;
  199.     end;
  200.  
  201.  
  202.  
  203.  
  204.